package com.dragon.client.controller.customer;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.client.config.annotation.Log;
import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.common.model.Update;
import com.dragon.logical.service.customer.AccountrecordssService;
import com.dragon.repository.domain.dto.AccountrecordssDTO;
import com.dragon.repository.domain.vo.AccountrecordssVO;
import com.dragon.repository.entity.Accountrecordss;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户 联系记录 管理
 * @author Charlotte
 */
@RestController
@Api(tags = "客户联系记录管理")
@RequestMapping("accountrecordss")
public class AccoutermentsController {

    @Autowired
    AccountrecordssService service;

    @GetMapping("list")
    @ApiOperation(value = "获取客户联系记录列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "search", value = "搜索参数", required = false, type = "string"),
            @ApiImplicitParam(name = "page", value = "页数", required = true, type = "int"),
            @ApiImplicitParam(name = "limit", value = "每页数量", required = true, type = "int")
    })
    public ResponseData<List<AccountrecordssDTO>> list(
            @RequestParam(required = false) String search,
            @RequestParam Integer page,
            @RequestParam Integer limit) {
        Page<Accountrecordss> accountPage = service.listAccountPage(search, page, limit);
        return ResponseData.success(AccountrecordssDTO.convertList(accountPage.getRecords()),  accountPage.getTotal());
    }

    @PostMapping("add")
    @ApiOperation("添加客户联系记录")
    @Log
    public ResponseData addAccount(
            @RequestBody @Validated(Insert.class) AccountrecordssVO vo) {
        return ResponseData.success(service.addAccount(AccountrecordssVO.convert(vo)));
    }

    @PostMapping("update")
    @ApiOperation("修改客户联系信息")
    @Log
    public ResponseData updateAccount(@RequestBody @Validated(Update.class)AccountrecordssVO vo){
        service.updateAccount(AccountrecordssVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("delete")
    @ApiOperation("删除客户联系信息")
    @Log
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "客户联系信息id", required = true, type = "int"),
            @ApiImplicitParam(name = " auditId", value = "审核人id", required = true, type = "int")
    })
    public ResponseData deleteAccount( @RequestParam Integer id, @RequestParam Integer projectId){
        service.deleteAccount(id);
        return ResponseData.success();
    }

}
